//
//  FCAboutAppVC.m
//  FundChain
//
//  Created by 肖浩然的mac on 2018/3/5.
//  Copyright © 2018年 RUIXIN. All rights reserved.
//

#import "FCAboutAppVC.h"
#import "FCUpdataAppContentVC.h"
@interface FCAboutAppVC ()<UITableViewDelegate,UITableViewDataSource>{
    UIView     *_viewNav;
}
/* tableView */
@property (strong, nonatomic) UITableView *tableView;
/* currentLabel */
@property (strong, nonatomic) UILabel *currentLabel;
@end

@implementation FCAboutAppVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    [FCLocalUserHelper saveIsMainVC:@"0"];
     [self setNav];
    [self setupUI];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 1) {
        
        FCUpdataAppContentVC *vc = [FCUpdataAppContentVC new];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2){
        NSString *urlStr = @"https://fund-chain.io/";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
    }
    
}
#pragma mark-UITableViewDataSource&UITableViewDelegate

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 4;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"abountAppCell"];
    
    NSArray *titleArr = @[@"Latest Fundchain Version",Localized(@"有什么新内容"),Localized(@"服务条款"),Localized(@"反馈和支持")];
    cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"abountAppCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel *leftLabel = [UILabel new];
    [cell addSubview:leftLabel];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.centerY.mas_equalTo(0);
    }];
    leftLabel.font = Kfont(32);
    leftLabel.textColor = kOrderColor;
    leftLabel.text = titleArr[indexPath.row];
    if (indexPath.row == 0) {
        leftLabel.hidden = YES;
//        UIImageView * _imageViewArro =[UIImageView new];
//        [cell addSubview:_imageViewArro];
//        [_imageViewArro setImage:[UIImage imageNamed:@"icon_next"]];
//        [_imageViewArro mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_offset (-30*KScreenWidthScale750);
//            make.width.mas_offset(16);
//            make.height.mas_offset(16);
//            make.centerY.mas_equalTo(0);
//        }];
//        //版本
//        UILabel *versionLabel = [UILabel new];
//        [cell addSubview:versionLabel];
//        [versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_equalTo(_imageViewArro.mas_left).offset(-8*KScreenWidthScale750);
//            make.centerY.mas_equalTo(0);
//        }];
//        versionLabel.font = Kfont(32);
//        versionLabel.textColor = kDarkBlackColor;
//        versionLabel.text = @"V1.0";
        
    }else if (indexPath.row == 1 || indexPath.row == 2){
        UIImageView * _imageViewArro =[UIImageView new];
        [cell addSubview:_imageViewArro];
        [_imageViewArro setImage:[UIImage imageNamed:@"icon_next"]];
        [_imageViewArro mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_offset (-30*KScreenWidthScale750);
            make.width.mas_offset(16);
            make.height.mas_offset(16);
            make.centerY.mas_equalTo(0);
        }];
        
    }else if (indexPath.row == 3){
        //网址
        UIButton *webLabel = [UIButton new];
        [cell addSubview:webLabel];
        [webLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-30*KScreenWidthScale750);
            make.centerY.mas_equalTo(0);
        }];
        webLabel.titleLabel.font =  Kfont(32);
        [webLabel setTitleColor:kDarkBlackColor forState:UIControlStateNormal];;
        [webLabel setTitle:@"https://fund-chain.io/" forState:UIControlStateNormal];
        [webLabel addTarget:self action:@selector(openSafari) forControlEvents:UIControlEventTouchUpInside];
        //分割线
        UIView *viewLine =[UIView new];
        [cell addSubview:viewLine];
        [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(webLabel);
            make.top.mas_equalTo(webLabel.mas_bottom);
            make.height.mas_equalTo(1);
        }];
        viewLine.backgroundColor =kDarkBlackColor;
        if (SCREEN_WIDTH == 320) {
            webLabel.titleLabel.font = Kfont(20);
        }

    }
    
    return cell;
}

-(void)openSafari{
    NSURL *url = [NSURL URLWithString:@"https://fund-chain.io/"];
    [[UIApplication sharedApplication]openURL:url];
    
}
-(void)setupUI{
   
    //logo
    UIImageView *logoImageView = [UIImageView new];
    [self.view addSubview:logoImageView];
    [logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_viewNav.mas_bottom).offset(80*KScreenHeightScale1334);
        make.centerX.mas_equalTo(0);
    }];
    logoImageView.image = [UIImage imageNamed:@"logo_about"];
    //当前版本
    UILabel *currentLabel = [UILabel new];
    self.currentLabel = currentLabel;
    [self.view addSubview:currentLabel];
    [currentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(logoImageView.mas_bottom).offset(40*KScreenHeightScale1334);
        make.centerX.mas_equalTo(0);
    }];
    
    currentLabel.text = Localized(@"当前版本：V1.0");
    currentLabel.font = Kfont(28);
    currentLabel.textColor = kGrayColor;
    [self tableView];
    //版权
    UILabel *copyRightLabel = [UILabel new];
    [self.view addSubview:copyRightLabel];
    [copyRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-40*KScreenHeightScale1334);
        make.centerX.mas_equalTo(0);
    }];
    copyRightLabel.text = @"©Copyright 2018 FundChain ";
    copyRightLabel.font = Kfont(28);
    copyRightLabel.textColor = kGrayColor;
}
//懒加载tableView
-(UITableView*)tableView{
    
    if(!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView ];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.currentLabel.mas_bottom).offset(120*KScreenHeightScale1334);
            make.left.mas_offset(0);
            make.right.mas_offset(0);
            make.height.mas_offset(500*KScreenHeightScale1334);
        }];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.scrollEnabled = NO;
        _tableView.backgroundColor = kWhiteColor;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}
#pragma mark-设置导航栏
-(void)setNav{
    self.navigationController.navigationBarHidden = YES;
    _viewNav =[UIView new];
    [self.view addSubview:_viewNav];
    [_viewNav mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            if (iPhoneX) {
                
                make.left.right.top.mas_equalTo(self.view.safeAreaInsets);
                make.height.mas_equalTo(88);
            }else{
                make.left.right.mas_equalTo(0);
                make.height.mas_equalTo(64);
                make.top.mas_equalTo(0);
            }
        }else{
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(64);
            make.top.mas_equalTo(0);
        }
        
    }];
    _viewNav.backgroundColor = kRedOrangeColor;
    
    UIButton *leftBtn = [UIButton new];
    [self.view addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15*KScreenWidthScale750);
        make.centerY.mas_equalTo(_viewNav.mas_centerY).offset(8);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [leftBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
    
    [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    //返回
    UILabel *backLabel = [UILabel new];
    
    [_viewNav addSubview:backLabel];
    [backLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_viewNav);
        make.centerY.mas_equalTo(_viewNav.mas_centerY).offset(8);
    }];
    backLabel.text = Localized(@"关于我们");
    backLabel.textColor = [UIColor whiteColor];
    backLabel.font = KOverstrikingfont(36);
    
    //事件
    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)leftBtnClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
@end
